﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class key : MonoBehaviour
{
    public InputField Instruction;
    public GameObject door;
    public GameObject keytip;
    public GameObject stopnote;
    public GameObject keysprite;
    public GameObject keyPrefab;
    public GameObject PickPos;
    public BoxCollider2D doorbox;
    public bool canPick=false;
    private void Start()
    {
        
        doorbox = door.GetComponent<BoxCollider2D>();
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        canPick = true;
    }
    private void OnTriggerExit2D(Collider2D collision)
    {
        canPick = false;
    }
    private void Update()
    {
        if(canPick)
        {
            if (Instruction.text == "pick")
            {
                GameObject pickkey = Instantiate(keyPrefab);
                pickkey.transform.parent = PickPos.transform;
                pickkey.transform.localPosition = new Vector3(0, 0.1f, 0);
                doorbox.isTrigger = true;
                Destroy(keytip);
                Destroy(stopnote);
                Destroy(keysprite);
            }
        }
        
    }
}
